tele9752wikiaorg-20200213-history
XxRR
Background: Know: Recognize: Prerequisites - IPv6 'Type-Length-Value formatting' 'Overview' Type-Length-Value formatting is widely deployed to specify and regulate how to express, encode, transmit and decode data transmitted in the network, espacially for optional information in some protocols( IPv4, SNMP etc ) and encoding rules( BER, ASN.1 ). This format allows a receiver to decode information without requiring any pre-knowledge of the size, content, or semantic meaning of the data. 'Structure' The Type-Length-Value(TLV),or known as Tag-Length-Value, is consist of the three following parts: 'Type' Type is usually a binary code which occupies 1 or 2 bytes. It indicates the kind of field that this part of the message represents. It usually contains much important information of the whole message,which can not be ignored. Here is a diagram showing more details below: The first picture shows the structure of the first byte and the particular meanings of each digit in it. b8 and b7 defines the data class. b6 shows whether the data structure is primitive or not. Particularly, if b6 equals "1"(constructed), that means it has one or more TLVs in the "Value" part. The rest of 5 digits express the tag(type) number, for example: 02: INTEGER 04: OCTET STRING See more in BER types If the tag value is larger than 31, that means we can't encode the number by only 5 digits. In this way, the last 5 digits in the first byte will be all "1" and another byte would be added. The structure as shown below: The b8 is a tag which represents the end of this "Type" area. In this way, we can express much larger number for Type. However, 1 byte is long enough in most situations. For example, ASN.1 defines PDU in TLV format. And in the PDU's header, it has a field named "error-status" and "error-index",which is useful to an analyser in network management. 'Length' Length indicates the size of the "Value" field,which is typically in 1 to 4 bytes as well. Normally, there are two different formats: the short form and the long form(Example:BER length and values). In the short form, the length of the "Length" field is fixed(1 byte). And in the long form ,we using the last 7 digits in first byte to indicate how many additional bytes are there in the "Length" part. So we can easily locate the next field followed. The "Length" part in the encoding format is also signicant for determing the end of "Value" field. Analyser only needs to abstract the value in the "Length" part and count the number in the "Value" field instead of recognising all the content or searching the symbol of ending in "Value" field, which increases the efffciency of the reciever. 'Value' The "Value" part is a variable-sized series of bytes which contains data for this part of the message1. The detailed format depends on the specific data it presenting. 'Advantages of TLV' *The TLV formatting provisdes an entire strict standard for definition of data structure during the storing and transmission. *The reciever just focuses on the value it really interested in paiticular locations and may not need to regonise all the field existing in a given packet. *It is much flexible in the packet size when compaired to UDP/TCP, which has a static format. *TLV sequences are easily searched using generalized parsing functions. *New message elements which are received at an older node can be safely skipped and the rest of the message can be parsed. TLV elements can be placed in any order inside the message body. *TLV elements are typically used in a binary format which makes parsing faster and the data smaller. It is easier to generate XML from TLV to make human inspection of the data possible1. 'Examples' *A simple example to show the structure for TLV formatting: If an AID string is given: 9F0607A0000000031010 , so the "9F06" is the "Type" field and "07" indicates its length of "Value". The true value of this AID is "A0000000031010",which is seven bytes actually. *Another example is SNMP protocol,which uses TLV to encode lists of objects being get or set as well as the fixed part of its header. A structure of IPv4 options in TLV format is shown below2: *See more TLV examples 'Reference' 1 Introduction of TLV Wikipedia, http://en.wikipedia.org/wiki/Type-length-value 2 The TCP/IP Guide-IP datagram options and option format, http://www.tcpipguide.com/free/t_IPDatagramOptionsandOptionFormat.htm Category:All